<template>
	<view>
		<!-- 自定义导航 -->
		<uni-nav-bar leftIcon="back" statusBar :border="false">
			<view class="w-100" >
				<view class="flex align-end  w-100 "style="height: 100rpx;" >
				  <text class="iconfont icon-fanhui"  @click="navigateToindex(index)" ></text>
				</view>
			<view class="flex align-center justify-center w-100 " >
				所有人可见
				<text class="iconfont icon-shezhi"> </text>
			</view>
			</view>
		</uni-nav-bar>
		<!-- 文本域 --> 
		<textarea v-model="content" placeholder="说一句话吧~" class="uni-textarea px-2" />
		<!-- 多图上传 -->
		 <upload-image @change="changeImage"></upload-image> 
		<!-- 底部操作条 -->
		 <view class="fixed-bottom bg-white flex align-center" style="height: 85rpx;">
			<view class="iconfont icon-caidan footer-btn animate__animated " hover-class="animate__jello"></view>
			<view class="iconfont icon-huati footer-btn animate__animated" hover-class="animate__jello"></view>
			<view class="iconfont icon-tupian footer-btn animate__animated" hover-class="animate__jello"></view>
			
			<view class="bg-main text-white ml-auto flex justify-center align-center rounded mr-2 animate__animated " style="width: 140rpx ;height: 60rpx;" hover-class="animate__jello" @click="submit()">发送</view>
		</view>
	</view>
</template>

<script>
	import $T from '@/common/time.js'
	import uniNavBar from '@/components/uni-ui/uni-nav-bar/uni-nav-bar.vue'
	import uploadImage from '@/components/common/upload-image.vue'
	export default {
		components:{
			
			uploadImage
		},
		data() {
			return {
				demo:[],
				id:"",
				content:"",
				imageList:[],
				username:"",
				userpic:"",
				title:"",
				titlepic:[],
				comment_count:0,
				isFollow:false,
				newstime:1570783530,
				share_num:0,
				support:{
					"type":"",
					"support_count":0,
					"unsupport_count":0
				},
			}
		},
		//过滤器
		 filters:{
			 formatTime(value){
				 return $T.gettime(value);
			 }
		 },
		onLoad() {
			this.getdata()
		},
		methods: {
			//返回
			navigateToindex(index){
				 uni.navigateBack()
			},
			// 选中图片
		    changeImage(e){
				this.imageList=e
				
			},
			//先把这个人的头像和昵称导出来
			async getdata()
			{
					const res = await uniCloud.callFunction({
						name: "userinformation",
						data: {
							action: 'getOne',
							id:this.$store.state.loginsStatus
						}
					})
					this.demo=res.result.data[0]
					console.log(this.demo)
				
			},
			
			getTime(){
			var date = new Date(),
			year = date.getFullYear(),
			month = date.getMonth() + 1,
			day = date.getDate(),
			hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
			minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
			second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
			month >= 1 && month <= 9 ? (month = "0" + month) : "";
			day >= 0 && day <= 9 ? (day = "0" + day) : "";
			var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
			return timer;
			},
			
			async submit(){
				console.log(this.demo.id)
				const res = await uniCloud.callFunction({
					name: 'tiezi',
					data: {
						action:'add',
						id:this.demo.id,
						comment_count:this.comment_count,
						isFollow:false,
						newstime:this.getTime(),
						share_num:this.share_num,
						support:this.support,
						username:this.demo.username,
						userpic:this.demo.userpic,
						title:this.content,
						titlepic:this.imageList
					}
				})
				uni.showToast({
					title: '发送成功',
					icon: 'none'
				})
			}
		}
	}
</script>

<style>
.footer-btn{
	width: 86rpx;
	height: 86rpx;
	display: flex;
	justify-content: center;
	align-content: center;
	font-size: 50rpx;
}
</style>
